package com.vue.designPatterns.singleton;

/**
 * Created by Administrator on 2019/3/14.
 * 单例设计模式-懒汉式,先声明,使用的时候再创建,线程不安全
 */
public class Singleton {

    private static Singleton singleton = null;

    //私有构造
    private Singleton(){}

    public static Singleton getSingleton() {
        /*if (singleton == null) {
            singleton = new Singleton();
        }*/
        //加一个锁,安全一些
        if (singleton == null) {
            synchronized (Singleton.class) {
                singleton = new Singleton();
            }
        }
        return singleton;
    }

}
